#ifndef COMMSYS_MGR_HPP
#define COMMSYS_MGR_HPP

#include "comm_interface.hpp"
#include <memory>
#include <vector>
#include <unordered_map>
#include <thread>
#include <mutex>
#include <condition_variable>

class CommSystemManager {
public:
    static CommSystemManager& getInstance();
    
    CommSystemManager(const CommSystemManager&) = delete;
    CommSystemManager& operator=(const CommSystemManager&) = delete;
    CommSystemManager(CommSystemManager&&) = delete;
    CommSystemManager& operator=(CommSystemManager&&) = delete;
    

    void addInterface(const std::string& name, std::shared_ptr<CommInterface> interface);
    void removeInterface(const std::string& name);
    
    std::shared_ptr<CommInterface> getInterface(const std::string& name);
    
    bool initializeAll();
    void shutdownAll();
    void startMonitoring();
    void stopMonitoring();
    
private:
    CommSystemManager() = default;
    ~CommSystemManager();
    
    void monitoringThreadFunc();
    
    std::unordered_map<std::string, std::shared_ptr<CommInterface>> interfaces_;
    std::mutex interfacesMutex_;
    
    std::thread monitorThread_;
    std::atomic<bool> monitoring_{false};
};

#endif // SYSTEM_MGR_HPP